<template>
    <!-- 修改资料 -->
    <div>
        <el-form label-width="100px" :model="form" label-position="right" ref="formRef" :rules="formRules">
            <el-row>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="编号" prop="number">
                        <el-input v-model="form.number"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="名称" prop="name">
                        <el-input v-model="form.name"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :xs="24" :sm="18" :md="18" :lg="18" :xl="18">
                    <el-form-item label="类别" prop="codeKind">
                        <!-- <tableselect v-model="form.codeKind" @handle="acceptData" :fileName="fileName"
                                    :codekind="form.codeKind"></tableselect> -->
                        <sc-table-select v-model="codeKindRows" :apiObj="apiObj" :fileName="fileName" :table-width="700"
                            :props="tableProps" @change="change" :defaultSelected="form.codeKindName">
                        </sc-table-select>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="6" :md="6" :lg="6" :xl="6">
                </el-col>
            </el-row>
            <el-row>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="自定义1" prop="customer1">
                        <el-input v-model="form.customer1"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="自定义2" prop="customer2">
                        <el-input v-model="form.customer2"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="自定义3" prop="customer3">
                        <el-input v-model="form.customer3"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="自定义4" prop="customer4">
                        <el-input v-model="form.customer4"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="备注">
                        <el-input v-model="form.remark"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="状态" prop="status">
                        <el-switch v-model="form.status" size="large" inline-prompt :active-icon="Check"
                            :inactive-icon="Close" active-value="normal" inactive-value="disable" />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="上传文件类型">
                        <el-select v-model="form.fileKind">
                            <el-option v-for="item in configData.fileKindList" :key="item.value" :label="item.label"
                                :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12">
                    <el-form-item label="另存为文件名">
                        <el-input v-model="form.saveToFileName"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-form-item label="上传附件" prop="file">
                <tsUpload @updateFile="updateFile" :imageUrl="imageUrl" @removeFile="removeFile"></tsUpload>
            </el-form-item>
        </el-form>
        <div class="button-position">
            <el-button @click="updateVisible">取 消</el-button>
            <el-button type="primary" @click="updateResourceFile(formRef)">确 定</el-button>
        </div>
    </div>
</template>

<script setup>
import { reactive, ref ,onMounted } from 'vue';
import { ElNotification } from 'element-plus';
import { Check, Close } from '@element-plus/icons-vue';
import tsUpload from '@/components/tsUpload/file.vue'
import Api from '@/api/model/system'
const visible = ref(true)

const emit = defineEmits(['updatetable'])
const props = defineProps({
    paramsData: {
        type: Object,
        defalut: {}
    }
})
const imageUrl = reactive({
    name:'',
    url:''
})
const apiObj = ref(Api.select.query)
const fileName = ref('ResourceFileKindTreeReport')
const tableProps = {
    label: 'name',
    value: 'id',
}
const codeKindRows = ref({})


// 添加用户数据的对象
const form = ref({
});
const configData = ref({})
const formRef = ref()
const formRules = reactive({
    // name: [
    //       { required: true, message: "请输入名称", trigger: "blur" },
    //     ],
    // codeKind: [
    //       { required: true, message: "请输入类别", trigger: "blur" },
    //     ],
})

onMounted(()=>{
    getInit()
})

const getInit = async() =>{
    let res = await Api.resourcefile.detail.post(props.paramsData)
    if(res.code == 200 ){
        form.value = res.data
        imageUrl.url = res.data.fileFullPath
        imageUrl.name = res.data.fileName
        configData.value = res.configData
    }
}

const change = (val) =>{
    form.value.codeKindId = val.id
}
const updateFile = (val) =>{
    form.value.file = val
}
const removeFile = () => {
    form.value.file = undefined
    form.value.deleteFlag = '1'
}
const restAddFormData = () => {
    formRef.value.resetFields();
}

const updateVisible = () => {
    emit('updatetable')
}


// 上传
const updateResourceFile = async (formRef) => {
    await formRef.validate((valid, fields) => {
        if (valid) {
            updateResourceFileData();

        }
    })
}

const updateResourceFileData = async () => {
    var params = {
        bean: form.value,
    }
    var res = await Api.resourcefile.update.post(params);
    if (res.code == 200) {
        restAddFormData()
        ElNotification.success({ title: '', message: '添加成功！', duration: 2000 });
        emit('updatetable',true)
    }
}

</script>

<style lang="less" scoped>
.el-dialog__wrapper {
    pointer-events: none;
}

.el-dialog {
    pointer-events: auto;
}
</style>

